{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.1"
  },
  "orig_nbformat": 4,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.9.1 64-bit"
  },
  "interpreter": {
   "hash": "ae7dbc91df3af0185ffb34e3fe12035cb4fadd9b684f5beca1182a2e24aafe6e"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "source": [
    "import csv\r\n",
    "import pandas as pd\r\n",
    "class1 = {}\r\n",
    "with open('class1.csv', 'rt') as f:\r\n",
    "    cr = csv.reader(f)\r\n",
    "    for row in cr:\r\n",
    "        class1[row[0]] = [row[1]]\r\n",
    "gender = {}\r\n",
    "with open('2020Gender.csv', 'rt') as f:\r\n",
    "    cr = csv.reader(f)\r\n",
    "    for row in cr:\r\n",
    "        gender[row[0]] = row[1]\r\n",
    "ans={'M':0,'F':0}\r\n",
    "out=[]\r\n",
    "for i in class1.keys():\r\n",
    "    out.append((i,class1[i][0],gender[i]))\r\n",
    "    class1[i].append(gender[i])\r\n",
    "    ans[gender[i]]+=1\r\n",
    "print(ans['M'],'男，',ans['F'],'女')\r\n",
    "out.insert(0,['学号','姓名','性别'])\r\n",
    "with open('1.csv', 'wt') as f2:\r\n",
    "    cw = csv.writer(f2)\r\n",
    "    #采用writerow()方法\r\n",
    "    # for item in out:\r\n",
    "    #     cw.writerow(item)  #将列表写到csv文件的一行\r\n",
    "    #或采用writerows()方法\r\n",
    "    cw.writerows(out)\r\n",
    "ttt=pd.read_csv('1.csv', encoding=\"GBK\")"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "36 男， 13 女\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "source": [
    "ttt"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "              学号    姓名 性别\n",
       "0   202083290219   管润达  M\n",
       "1   202083290331   史骁晗  M\n",
       "2   202083290503   胡天乐  M\n",
       "3   202083290054   孙世昂  M\n",
       "4   202083290122   刘天睿  M\n",
       "5   202083290158   刘恩彤  M\n",
       "6   202083290143    曹杰  M\n",
       "7   202083290223   华凌一  M\n",
       "8   202083290044   叶苁林  F\n",
       "9   202083290091   杜宇豪  M\n",
       "10  202083290299   王子豪  M\n",
       "11  202083290098   茅诗铭  F\n",
       "12  202083290374    刘辉  M\n",
       "13  202083290385   沈禹豪  M\n",
       "14  202083290452    陈政  M\n",
       "15  202083290512   戴亚鑫  M\n",
       "16  202083290084    纪苇  M\n",
       "17  202083290187  王高振洋  M\n",
       "18  202083290298   王思程  M\n",
       "19  202083290137   高一民  M\n",
       "20  202083290514    王健  M\n",
       "21  202083290341   陈凯铭  M\n",
       "22  202083290211   郑韶婷  F\n",
       "23  202083290400   鲁哲豪  M\n",
       "24  202083290409   刘文浩  M\n",
       "25  202083290010   刘萌轩  F\n",
       "26  202083290203   李施玥  F\n",
       "27  202083290077    王婧  F\n",
       "28  202083290155   甘宜旺  M\n",
       "29  202083290178   黄钱骏  M\n",
       "30  202083290516   王苏杭  M\n",
       "31  202083290075   丁勇男  M\n",
       "32  202083290128   陈梓萱  F\n",
       "33  202083290113    冯悦  F\n",
       "34  202083290312   佘自然  M\n",
       "35  202083290176    徐骞  F\n",
       "36  202083290408   刘长润  M\n",
       "37  202083290159   朱思嘉  F\n",
       "38  202083290004   王子曰  M\n",
       "39  202083290344   李俊杰  M\n",
       "40  202083290164   陆洪伟  M\n",
       "41  202083290174   贺苏阳  M\n",
       "42  202083290129    李念  F\n",
       "43  202083290101   柳钰恒  F\n",
       "44  202083290059   陆嘉辉  M\n",
       "45  202083290125   许明智  M\n",
       "46  202083290412   庄鑫驰  M\n",
       "47  202083290161   陈笑颖  F\n",
       "48  202083290135   林雨辰  M"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>学号</th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>202083290219</td>\n",
       "      <td>管润达</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>202083290331</td>\n",
       "      <td>史骁晗</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>202083290503</td>\n",
       "      <td>胡天乐</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>202083290054</td>\n",
       "      <td>孙世昂</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>202083290122</td>\n",
       "      <td>刘天睿</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>202083290158</td>\n",
       "      <td>刘恩彤</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>202083290143</td>\n",
       "      <td>曹杰</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>202083290223</td>\n",
       "      <td>华凌一</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>202083290044</td>\n",
       "      <td>叶苁林</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>202083290091</td>\n",
       "      <td>杜宇豪</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>202083290299</td>\n",
       "      <td>王子豪</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>202083290098</td>\n",
       "      <td>茅诗铭</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>202083290374</td>\n",
       "      <td>刘辉</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>202083290385</td>\n",
       "      <td>沈禹豪</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>202083290452</td>\n",
       "      <td>陈政</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>202083290512</td>\n",
       "      <td>戴亚鑫</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>202083290084</td>\n",
       "      <td>纪苇</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>202083290187</td>\n",
       "      <td>王高振洋</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>202083290298</td>\n",
       "      <td>王思程</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>202083290137</td>\n",
       "      <td>高一民</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>202083290514</td>\n",
       "      <td>王健</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>202083290341</td>\n",
       "      <td>陈凯铭</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>202083290211</td>\n",
       "      <td>郑韶婷</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>202083290400</td>\n",
       "      <td>鲁哲豪</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>202083290409</td>\n",
       "      <td>刘文浩</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>202083290010</td>\n",
       "      <td>刘萌轩</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>202083290203</td>\n",
       "      <td>李施玥</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>202083290077</td>\n",
       "      <td>王婧</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>202083290155</td>\n",
       "      <td>甘宜旺</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>202083290178</td>\n",
       "      <td>黄钱骏</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>202083290516</td>\n",
       "      <td>王苏杭</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>202083290075</td>\n",
       "      <td>丁勇男</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>202083290128</td>\n",
       "      <td>陈梓萱</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>202083290113</td>\n",
       "      <td>冯悦</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>202083290312</td>\n",
       "      <td>佘自然</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>202083290176</td>\n",
       "      <td>徐骞</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>202083290408</td>\n",
       "      <td>刘长润</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>202083290159</td>\n",
       "      <td>朱思嘉</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>202083290004</td>\n",
       "      <td>王子曰</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>202083290344</td>\n",
       "      <td>李俊杰</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>202083290164</td>\n",
       "      <td>陆洪伟</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>202083290174</td>\n",
       "      <td>贺苏阳</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>202083290129</td>\n",
       "      <td>李念</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>202083290101</td>\n",
       "      <td>柳钰恒</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>202083290059</td>\n",
       "      <td>陆嘉辉</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>202083290125</td>\n",
       "      <td>许明智</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>202083290412</td>\n",
       "      <td>庄鑫驰</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>202083290161</td>\n",
       "      <td>陈笑颖</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>202083290135</td>\n",
       "      <td>林雨辰</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 2
    }
   ],
   "metadata": {}
  }
 ]
}